import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		usrid: uni.getStorageSync('usrid') || null,
		userInfo: uni.getStorageSync('userInfo') || null,
		orderinfo: null,
	},
	mutations: {
		login(state, provider) {
			state.userInfo = provider;
			state.usrid = provider['id'];
			uni.setStorage({ //缓存用户登陆状态
					key: 'userInfo',
					data: provider
				}),
				uni.setStorage({ //缓存用户登陆状态
					key: 'usrid',
					data: provider['id']
				})
		},
		logout(state) {
			state.usrid = null;
			state.userInfo = null;
			uni.removeStorage({
					key: 'userInfo'
				}),
				uni.removeStorage({
					key: 'usrid'
				})
		},
		setorderinfo(state, provider) {
			state.orderinfo = provider;
		},
	},
	actions: {

	}
})

export default store